<?php
namespace app\index\controller;

use app\BaseController;
use think\facade\Request;
use think\facade\View;
use app\index\model\Member;
use think\facade\Session;

class Login extends BaseController{
    public function index(){
        if (!Request::post()) {
            return View::fetch();
        }
        $post = Request::post();
        $filter[] = ['uname',"like","%".$post['username']."%"];
        $memberInfo = Member::getMemberInfoOne($filter);
        if (empty($memberInfo)) {
            echo '用户不存在';
            redirect(url('index/login/index'))->send();
        }
        if ($memberInfo->upwd == $post['password']) {
            Session::set("user_id",$memberInfo->id);
            redirect(url('index/Index/index'))->send();
        } else {
            redirect(url('index/login/index'))->send();
        }
    }
}